package com.weatherstation;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.context.annotation.Bean;

/**
 * 气象站数据管理系统主启动类
 * 
 * @author WeatherStation Team
 * @version 1.0.0
 */
@SpringBootApplication
@EnableScheduling
@MapperScan("com.weatherstation.mapper")
public class WeatherStationApplication {

    public static void main(String[] args) {
        SpringApplication.run(WeatherStationApplication.class, args);
        System.out.println("\n" +
                "=================================================\n" +
                "    气象站数据管理系统启动成功!\n" +
                "    访问地址: http://localhost:8080/api\n" +
                "    API文档: http://localhost:8080/api/swagger-ui.html\n" +
                "=================================================\n");
    }

    /**
     * 配置跨域访问
     */
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowedOrigins("http://localhost:3000", "http://localhost:5173")
                        .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                        .allowedHeaders("*")
                        .allowCredentials(true)
                        .maxAge(3600);
            }
        };
    }
}